//
//  SISSHouseTakeLookRecordViewController.m
//  SISSAPP
//
//  Created by 优房网 on 2017/8/31.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSHouseTakeLookRecordViewController.h"
#import "SISSImportantHouseTakeLookRecordCell.h"
#import "SISSHouseTakeLookDetailViewController.h"
#import "SISSAddHouseTakeLookViewController.h"
#import "SISSNetworkingManager+HouseProgress.h"
#import "SISSHouseProgressModel.h"
#import "SISSHouseProgressRecordInfoModel.h"

static NSString *impotantHouseTakeLookRecordCellReuseID = @"impotantHouseTakeLookRecordCellReuseID";
@interface SISSHouseTakeLookRecordViewController ()
/* 带看模型数组 */
@property (strong, nonatomic) NSArray<SISSHouseTakeLookModel *> *takeLookArr;

@end
@interface SISSHouseTakeLookRecordViewController ()

@end

@implementation SISSHouseTakeLookRecordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.tableView registerClass:[SISSImportantHouseTakeLookRecordCell class] forCellReuseIdentifier:impotantHouseTakeLookRecordCellReuseID];
    
    WeakSelf
    [kSISSRefresh prepareHeaderRefresh:self.tableView loadDataBlock:^{
        kSISSRefresh.refreshType = SISSRefressTypeUpDown;
        [weakSelf upDownLoadData];
    }];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self requestHouseTakeLookRecordData];
}

- (void)addRecordButtonDidClickAction {
    [super addRecordButtonDidClickAction];
    if (self.houseProgressRecordInfoModel.businessStatus == 2) {
        [self alertActionAlertWithTitle:@"提示" message:@"对方已开启拒绝接收您的请求"];
        return;
    }
    SISSAddHouseTakeLookViewController *vc = [[SISSAddHouseTakeLookViewController alloc] init];
    vc.houseProgressModel = self.houseProgressModel;
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - UITableViewDelegate & UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.takeLookArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    SISSImportantHouseTakeLookRecordCell *cell = [tableView dequeueReusableCellWithIdentifier:impotantHouseTakeLookRecordCellReuseID forIndexPath:indexPath];
    cell.isHiddenCheckButton = YES;
    cell.takeLookModel = self.takeLookArr[indexPath.row];
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
    SISSHouseTakeLookDetailViewController *vc = [[SISSHouseTakeLookDetailViewController alloc] init];
    vc.houseProgressModel = self.houseProgressModel;
//    vc.brokerState = self.takeLookArr[indexPath.row].brokerState;
    vc.takeLookModel = self.takeLookArr[indexPath.row];
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - 加载数据
- (void)upDownLoadData {
    
    [self requestHouseTakeLookRecordData];
}

#pragma mark -- 获取房源带看记录数据
- (void)requestHouseTakeLookRecordData {

    WeakSelf
    [kNetworkManager requestHouseTakelookRecordWithAhbpId:self.houseProgressModel.ahbpId success:^(NSArray<SISSHouseTakeLookModel *> *takeLookArr) {
        weakSelf.takeLookArr = takeLookArr;
        
        [[NSOperationQueue mainQueue] addOperationWithBlock:^{
            [weakSelf.tableView reloadData];
            [weakSelf.tableView.mj_header endRefreshing];
        }];
        
    } failed:^(NSError *error) {
        
        [weakSelf.tableView.mj_header endRefreshing];
        NSLog(@"%@",error);
    }];

} 


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
